<?php
	if ((!defined("ADMIN-AREA")) || (!in_array(SHOWVIEW,$_SESSION['access']))) {
		die("No data");
	} else {
		unset($_SESSION['access']);
	}

	include_once "modul/funct_stat.php";
	
	if (ACT=="edit") {
		$kode = (int) $_GET['kode'];
		$sql = "SELECT * FROM tbl_upload WHERE idx='".$kode."' ORDER BY tanggal DESC LIMIT 1";
		$qry = mysql_query($sql);
		$row = mysql_fetch_object($qry);

		$namax = explode("[spasi]",$row->data);
		$nama = $namax[1];
		$ukuran = $namax[2];
		$thum = $namax[0];
		$tipe = $row->tipe;
		$url = $namax[3];
		$target = (empty($namax[4])) ? "_self" : $namax[4];
		$posisi = $namax[2];
		$form_stat = "Edit";
		
		$tanggal_mulai = $row->tanggal_mulai;
		$tanggal_selesai = $row->tanggal_selesai;
		
		$haritampilnya = explode("[break]",$row->hari_aktif);
		$jam_mulai = explode(":",$row->jam_aktif_mulai);
		$jam_selesai = explode(":",$row->jam_aktif_selesai);
	} else {
		$form_stat = "Input";
		$target = "_self";
		
		$haritampilnya = array();
		
		$tanggal_mulai = "0000-00-00";
		$tanggal_selesai = "0000-00-00";
		
	}
	$opt_target = array("_parent", "_top", "_blank", "_self");

	if ((ACT=="tambah") || (ACT=="edit")) {
?>
<form action="<?php echo $path; ?>ver_banner.php?show=<?php echo SHOW; ?>&amp;showview=<?php echo SHOWVIEW; ?>" method="post" enctype="multipart/form-data" name="form1" onsubmit="MM_validateForm('<?php echo $BANNER_TITLE; ?>','','R','<?php echo $BANNER_URl; ?>','','R','<?php echo $BANNER_POSITION; ?>','','R','<?php echo $BANNER_URl_TARGET; ?>','','R','<?php echo $BANNER_SHOW_DATE_BEGIN; ?>','','R','<?php echo $BANNER_SHOW_DATE_END; ?>','','R','<?php echo $BANNER_UPLOAD; ?>','','R');return document.MM_returnValue">
  <table width="95%" border="0" align="center" cellpadding="4" cellspacing="0" class="content-arial">
    <tr> 
      <td width="50%" rowspan="2" valign="top"> <table width="95%" border="0" align="right" cellpadding="4" cellspacing="0" class="content-arial">
          <tr> 
            <td width="34%" valign="middle" nowrap="nowrap"><div align="right"><?php echo $BANNER_TITLE; ?></div></td>
            <td width="3%" valign="middle"><div align="center">:</div></td>
            <td width="63%" valign="middle"><div align="left">
              <input name="nama" type="text" id="<?php echo $BANNER_TITLE; ?>" size="30" value="<?php echo $nama; ?>" class="input-title" />
            </div></td>
          </tr>
          <tr> 
            <td nowrap="nowrap"><div align="right"><?php echo $BANNER_URl; ?></div></td>
            <td><div align="center">:</div></td>
            <td><div align="left">
              <input name="url" type="text" id="<?php echo $BANNER_URl; ?>" size="30" value="<?php echo $url; ?>" />
            </div></td>
          </tr>
          <tr>
						<td nowrap="nowrap"><div align="right"><?php echo $BANNER_POSITION; ?></div></td>
          	<td><div align="center">:</div></td>
          	<td><div align="left">
          	    <select name="posisi" id="<?php echo $BANNER_POSITION; ?>">
          	      <option value="AKi" <?php if ($posisi=="AKi") echo "selected"; ?>>AKi - Header Kiri</option>
          	      <option value="ATe" <?php if ($posisi=="ATe") echo "selected"; ?>>ATe - Header Tengah</option>
          	      <option value="AKa" <?php if ($posisi=="AKa") echo "selected"; ?>>AKa - Header Kanan</option>
          	      <option value="MKiA" <?php if ($posisi=="MKiA") echo "selected"; ?>>MKiA - Menu Kiri Atas</option>
          	      <option value="MKiT" <?php if ($posisi=="MKiT") echo "selected"; ?>>MKiT - Menu Kiri Tengah</option>
          	      <option value="MKiB" <?php if ($posisi=="MKiB") echo "selected"; ?>>MKiB - Menu Kiri Bawah</option>
          	      <option value="MTeA" <?php if ($posisi=="MTeA") echo "selected"; ?>>MTeA - Content Atas</option>
          	      <option value="MTeT" <?php if ($posisi=="MTeT") echo "selected"; ?>>MTeT - Content Tengah</option>
          	      <option value="MTeB" <?php if (($posisi=="MTeB") || ($posisi=="")) echo "selected"; ?>>MTeB - Content Bawah</option>
          	      <option value="MKaA" <?php if ($posisi=="MKaA") echo "selected"; ?>>MKaA - Menu Kanan Atas</option>
          	      <option value="MKaT" <?php if ($posisi=="MKaT") echo "selected"; ?>>MKaT - Menu Kanan Tengah</option>
          	      <option value="MKaB" <?php if ($posisi=="MKaB") echo "selected"; ?>>MKaB - Menu Kanan Bawah</option>
          	      <option value="BKi" <?php if ($posisi=="BKi") echo "selected"; ?>>BKi - Footer Kiri</option>
          	      <option value="BTe" <?php if ($posisi=="BTe") echo "selected"; ?>>BTe - Footer Tengah</option>
          	      <option value="BKa" <?php if ($posisi=="BKa") echo "selected"; ?>>BKa - Footer Kanan</option>
       	        </select>
   	        </div></td>
          </tr>
          <tr>
          <td nowrap="nowrap"><div align="right"><?php echo $BANNER_URl_TARGET; ?></div></td>
          	<td><div align="center">:</div></td>
          	<td><div align="left">
          	  <select name="target" id="<?php echo $BANNER_URl_TARGET; ?>">
          	    <?php
			foreach($opt_target as $val){
				echo $target . " " . $val;
				printf("<option value=\"%s\" %s>%s</option>\n", $val, ($target==$val ? "selected" : ""), $val);
			}
			?>
        	    </select>
       	    </div></td>
         	</tr>
          <tr>
            <td valign="top" nowrap="nowrap"><div align="right"><?php echo $BANNER_SHOW_TIME; ?></div></td>
            <td valign="top"><div align="center">:</div></td>
            <td valign="top" nowrap="nowrap"><table width="100%" border="0" cellspacing="0" cellpadding="2">
							<tr>
								<td nowrap="nowrap"><sup class="style1">(1)</sup><?php echo $BANNER_SHOW_DATE_BEGIN; ?></td>
								<td>:</td>
								<td nowrap="nowrap"><div align="left">
								  <input name="tanggal_mulai" value="<?php echo $tanggal_mulai; ?>" readonly="readonly" type="text" id="<?php echo $BANNER_SHOW_DATE_BEGIN; ?>" size="15" /> 
								  <input name="tgl1" type="button" id="tgl1" value="..." />
							    </div></td>
							</tr>
							<tr>
								<td nowrap="nowrap"><sup class="style1">(1)</sup><?php echo $BANNER_SHOW_DATE_END; ?></td>
								<td>:</td>
							  <td nowrap="nowrap"><div align="left">
							    <input name="tanggal_selesai" value="<?php echo $tanggal_selesai; ?>" readonly="readonly" type="text" id="<?php echo $BANNER_SHOW_DATE_END; ?>" size="15" />
							    <input name="tgl2" type="button" id="tgl2" value="..." />
							    </div></td>
							</tr>
							<tr>
								<td valign="top" nowrap="nowrap"><sup class="style1">(2)</sup><?php echo $BANNER_SHOW_DAY; ?></td>
								<td valign="top">:</td>
								<td nowrap="nowrap">
								  <div align="left">
								    <?php
									$day = array("Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu", "Minggu");
									$x = 0;
									echo '<table border="0">';
									echo '<tr>';
									foreach ($day as $hari) {
										echo '<td><input name="hari[]" id="hari[]" type="checkbox" value="'.$hari.'"';
										if (in_array($hari,$haritampilnya))
											echo ' checked';
										echo ' /> '.$hari."</td>";
										$x++;
										if ($x==3) {
											echo "</tr><tr>";
											$x = 0;
										}
									}
									echo '</tr></table>';
								?>
						        </div></td>
							</tr>
							<tr>
								<td valign="top" nowrap="nowrap"><sup class="style1">(3)</sup><?php echo $BANNER_SHOW_TIME_BEGIN; ?></td>
								<td>:</td>
								<td nowrap="nowrap"><div align="left">
									<select name="j1" id="j1">
									  <?php
									for ($i=0;$i<=11;$i++) {
										$cc = $i;
										if ($i<=9)
											$cc = "0".$i;
										echo '<option value="'.$cc.'"';
										if ($jam_mulai[0]==$cc)
											echo ' selected';
										echo '>'.$cc.'</option>';
									}
								?>
								  </select>
									: 
									<select name="j2" id="j2">
									  <?php
									for ($i=0;$i<=59;$i++) {
										$cc = $i;
										if ($i<=9)
											$cc = "0".$i;
										echo '<option value="'.$cc.'"';
										if ($jam_mulai[1]==$cc)
											echo ' selected';
										echo '>'.$cc.'</option>';
									}
								?>
								  </select> 
									AM <?php echo $BANNER_SHOW_TIME_BETWEEN; ?>
									<select name="j3" id="j3">
									  <?php
									for ($i=0;$i<=11;$i++) {
										$cc = $i;
										if ($i<=9)
											$cc = "0".$i;
										echo '<option value="'.$cc.'"';
										if ($jam_selesai[0]==$cc)
											echo ' selected';
										echo '>'.$cc.'</option>';
									}
								?>
								  </select>
									: 
									<select name="j4" id="j4">
									  <?php
									for ($i=0;$i<=59;$i++) {
										$cc = $i;
										if ($i<=9)
											$cc = "0".$i;
										echo '<option value="'.$cc.'"';
										if ($jam_selesai[1]==$cc)
											echo ' selected';										
										echo '>'.$cc.'</option>';
									}
								?>
								  </select> 
									PM </div></td>
							</tr>
						</table></td>
          </tr>
          <tr> 
            <td nowrap="nowrap"><div align="right"><?php echo $BANNER_UPLOAD; ?></div></td>
            <td><div align="center">:</div></td>
            <td><input name="upbanner" type="file" id="<?php echo $BANNER_UPLOAD; ?>">
            <?php echo $$BANNER_TIPS_UPLOAD; ?></td>
          </tr>
          <tr> 
            <td nowrap="nowrap">&nbsp;</td>
            <td>&nbsp;</td>
            <td><div align="left"> 
            <input type="submit" name="submit" id="submit" value="<?php echo $DEV_CTRL_SUBMIT; ?>" />
              <input type="reset" name="Reset" value="<?php echo $DEV_CTRL_RESET; ?>" />
                <input name="act_ver" type="hidden" id="act_ver" value="<?php echo strtolower($form_stat); ?>">
                <input name="kode" type="hidden" id="kode" value="<?php echo $kode; ?>">
                <input name="nama_hid" type="hidden" id="nama_hid" value="<?php echo $thum; ?>">
                <input name="show" type="hidden" id="show" value="<?php echo SHOW; ?>" />
            </div></td>
          </tr>
      </table></td>
      <td width="58%" valign="top"><?php
		if (file_exists("data/ads/BN".$thum.".".$tipe)) {
			echo "Your Current Banner :<br />";
			echo "<img src=\"data/ads/BN".$thum.".".$tipe."\" border='0' width=\"100\">";
			$size = getimagesize("data/ads/BN".$thum.".".$tipe);
			$types = array(1 => 'GIF',2 => 'JPG',3 => 'PNG',4 => 'SWF',5 => 'PSD',6 => 'BMP',7 => 'TIFF(intel byte order)',8 => 'TIFF(motorola byte order)',9 => 'JPC',10 => 'JP2',11 => 'JPX',12 => 'JB2',13 => 'SWC',14 => 'IFF',15 => 'WBMP',16 => 'XBM');
			echo "<br />Image Status : <br />";
			echo "Name : ".$thum."<br />";
			echo "Width&nbsp;&nbsp;: ".$size[0]." px<br />";
			echo "Height : ".$size[1]." px<br />";
			echo "Atrribute : ".$types[$size[2]]."<br />";
			echo "Mime Type : ".$size['mime'];
		};
		echo "<br /><br />";
		if (ACT!="tambah") {
				echo "Status Banner :<br />";
				if ($tanggal_mulai=="0000-00-00")
					echo "Status Mulai : Banner Ditampilkan secara permanen";
				else
					echo "Status Mulai : ".date("d-m-Y",strtotime($tanggal_mulai));
				echo "<br />";
				if ($tanggal_selesai=="0000-00-00")
					echo "Status Selesai : Banner Ditampilkan secara permanen";
				else
					echo "Status Selesai : ".date("d-m-Y",strtotime($tanggal_selesai));
				echo "<br />Banner ditampilkan Hari : ";
				foreach($haritampilnya as $tampilhari) {
					if ($tampilhari) 
						$hr .= $tampilhari.", ";
				};
				echo substr($hr,0,-2);
				echo "<br />Jam Mulai Tampil : ";
				foreach($jam_mulai as $jm) {
					if ($jm) 
						$jmX .= $jm.":";
				};
				echo date("H:i",strtotime(substr($jmX,0,-1)))." AM";
				echo "<br />Jam Selesai Tampil : ";				
				foreach($jam_selesai as $js) {
					if ($js) 
						$jsX .= $js.":";
				};
				echo date("H:i",strtotime(substr($jsX,0,-1)))." PM";
		}
	?></td>
    </tr>
    <tr>
      <td valign="top">&nbsp;</td>
    </tr>
    <tr>
    	<td colspan="2" valign="top"><div align="center">
    		<table width="99%" border="0" align="right" cellpadding="0" cellspacing="2">
					<tr>
						<td><div align="left"><?php echo $BANNER_TIPS_HEADER; ?></div></td>
						</tr>
					<tr>
						<td><div align="left"><span class="style1"><sup>(1)</sup><?php echo $BANNER_TIPS_DATE; ?></span></div></td>
					</tr>
					<tr>
						<td><div align="left"><span class="style1"><sup>(2)</sup><?php echo $BANNER_TIPS_DAY; ?></span></div></td>
					</tr>
					<tr>
						<td><div align="left"><span class="style1"><sup>(3)</sup><?php echo $BANNER_TIPS_TIME; ?></span></div></td>
					</tr>
					<tr>
						<td><div align="left"></div></td>
					</tr>
					<tr>
						<td><div align="left"><?php echo $BANNER_TIPS_USAGE_PHP; ?><br />
						  <pre style="padding:2px; display:block; font-weight:bold; border: thin solid #FF9900; background-color:#FEDEBA; width:550px">echo banner($jum,$lebar,$panjang,$batas_tampil,$pj,$lb,$filenameOnly,$posisi)</pre>
						  <?php echo $BANNER_TIPS_USAGE_SMARTY; ?>
					    <pre style="padding:2px; display:block; font-weight:bold; border: thin solid #FF9900; background-color:#FEDEBA; width:625px">&lt;!--{banner jum=? lebar=? panjang=? batas_tampil=? pj=? lb=? filenameOnly=? posisi=?}--&gt;</pre>
							<ol>
							  <li>$jum = <?php echo $BANNER_USAGE_SUM; ?></li>
									<li>$lebar = <?php echo $BANNER_USAGE_WIDTH; ?></li>
									<li>$panjang = <?php echo $BANNER_USAGE_LENGTH; ?></li>
									<li>$batas_tampil = <?php echo $BANNER_USAGE_SHOW_LIMIT; ?></li>
									<li>$pj (false/true) = <?php echo $BANNER_USAGE_LENGTH_TF; ?></li>
									<li>$lb (false/true) = <?php echo $BANNER_USAGE_WIDTH_TF; ?></li>
									<li>$filenameOnly (false/true) = <?php echo $BANNER_USAGE_FILENAMEONLY_TF; ?></li>
									<li>$posisi = <?php echo $BANNER_USAGE_POSITION; ?></li>
						  </ol>
							<p>&nbsp;</p>
                        </div></td>
						</tr>
				</table>
	  </div></td>
   	</tr>
  </table>
</form>
<script type="text/javascript">
	Zapatec.Calendar.setup({
		inputField     :    "<?php echo $BANNER_SHOW_DATE_BEGIN; ?>",   // id of the input field
		button         :    "tgl1",  // What will trigger the popup of the calendar
		ifFormat       :    "%Y-%m-%d",       // format of the input field
		timeFormat     :    "24",
		showsTime      :    false,          //no time
		disableFunc    :    null, //the function to call
		onUpdate       :    null
	});
	Zapatec.Calendar.setup({
		inputField     :    "<?php echo $BANNER_SHOW_DATE_END; ?>",   // id of the input field
		button         :    "tgl2",  // What will trigger the popup of the calendar
		ifFormat       :    "%Y-%m-%d",       // format of the input field
		timeFormat     :    "24",
		showsTime      :    false,          //no time
		disableFunc    :    null, //the function to call
		onUpdate       :    null
	});
</script>
<?php
	} else {
		echo $queryData->cari_form($BANNER_SEARCH);
		$caridata = $queryData->cari_padaku("data","tipe");
		if (isset($_SESSION['isroot'])) {
			$sql1 = "SELECT * FROM tbl_upload WHERE RIGHT(`data`,6)='BANNER' ".$caridata." ORDER BY tanggal LIMIT ".$limitdown.",10";
			//$num = countme("tbl_upload WHERE RIGHT(`data`,6)='BANNER' ".$caridata);
		} else {
			$sql1 = "SELECT * FROM tbl_upload WHERE RIGHT(`data`,6)='BANNER' ".$caridata." ORDER BY tanggal LIMIT ".$limitdown.",10";
			//$num = $queryData->countme("tbl_upload WHERE RIGHT(`data`,6)='BANNER' ".$caridata."");
		}
?>
<table border="0" align="center" cellpadding="4" cellspacing="2" class="imagesSUB">
  <tr> 
    <th width="150" height="30" class="imagesSUB"> <div align="center"><?php echo $BANNER_TITLE; ?></div></th>
    <th width="120" class="imagesSUB"> <div align="center"><?php echo $BANNER_DATE_UPLOAD; ?></div></th>
    <th width="70" class="imagesSUB" nowrap="nowrap"> <div align="center"><?php echo $BANNER_POSITION; ?></div></th>
    <th width="70" class="imagesSUB" nowrap="nowrap"> <div align="center"><?php echo $BANNER_FILENAME; ?></div></th>
    <th width="50" class="imagesSUB"><div align="center"><?php echo $DEV_ACTION; ?></div></th>
  </tr>
  <?php	
		$qry1 = mysql_query($sql1);
		$numrow = mysql_num_rows($qry1);
		$num = 1;
		$x = 1;
		if ($numrow==0) {
			echo '<tr><th colspan="7">'.$DEV_NO_DATA.'</th></tr>';
		} else {
			while ($row1 = mysql_fetch_object($qry1)) {
				$nama = explode("[spasi]",$row1->data);
				$ukuran = $nama[2];
				$tipe = $row1->tipe;
				if (!empty($nama[3]))
					$url = $nama[3];
				else
					$url = "NONE"; 
				$data = $x % 2;
				if ($data==0)
					$dataX = "ganjil";
				else
					$dataX = "genap"; 
?>
  <tr valign="top" class="<?php echo $dataX; ?>" onmouseover="setBG('bg<?php echo $x; ?>','#FFFFDD')" onmouseout="setBG('bg<?php echo $x; ?>','')" id="bg<?php echo $x; ?>"> 
    <td title="URl: <?php echo $url; ?>"><div align="left"><?php echo $nama[1]; ?></div></td>
    <td><div align="center"><?php echo $row1->tanggal; ?></div>
    <div align="center"></div></td>
    <td> 
      <div align="center"><?php echo $nama[2]; ?></div></td>
    <td> 
      <div align="center"> 
				<?php
                if (file_exists("data/ads/BN".$nama[0].".".$row1->tipe)) {
                    echo "<a href=\"data/ads/BN".$nama[0].".".$row1->tipe."\" title=\"Download\"><img src='".$dev_path."images/download.gif' border='0'></a>";
                } else {
                    echo "Data Tidak ada";
                };
            ?>
      </div></td>
		<?php 
		echo $queryData->ctrl_data('','index.php?show='.SHOW.'&showview='.SHOWVIEW.'&act=edit&kode='.$row1->idx,$path.'ver_banner.php?show='.SHOW.'&amp;showview='.SHOWVIEW.'&amp;kode='.$row1->idx.'&amp;act_ver=Hapus'); ?>		
  </tr>
  <?php
				$x++;
 			}
		}
?>
</table>
<div align="center"><?php echo $queryData->next_prev($num,$pages_syarat,$limitdown); ?></div>
<?php
	}
?>
